package com.heima.wemedia.service.impl;

import com.heima.api.feign.IScheduleFeginClient;
import com.heima.model.common.enums.TaskTypeEnum;
import com.heima.model.schedule.dtos.Task;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.utils.common.ProtostuffUtil;
import com.heima.wemedia.service.WmNewsTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * TODO
 *
 * @Author mr.zhao
 * @Date 2025/6/22 22:08
 */
@Service
@Slf4j
public class WmNewsTaskServiceImpl implements WmNewsTaskService {
	@Autowired
	private IScheduleFeginClient scheduleFeginClient;
	/**
	 * 添加文章自动发布任务
	 *
	 * @param id
	 * @param publishTime
	 */
	@Override
	public void addNewsToTask(Integer id, Date publishTime) {
		log.info("添加文章自动发布任务,文章id: {},发布时间: {}",id,publishTime);
		Task task = new Task();
		task.setExecuteTime(publishTime.getTime());
		task.setTaskType(TaskTypeEnum.NEWS_SCAN_TIME.getTaskType());
		task.setPriority(TaskTypeEnum.NEWS_SCAN_TIME.getPriority());
		WmNews wmNews = new WmNews();
		wmNews.setId(id);
		task.setParameters(ProtostuffUtil.serialize(wmNews));
		scheduleFeginClient.saveTask(task);
		log.info("添加文章自动发布任务成功");
	}
}
